package at.fhv.components.save;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import at.fhv.framework.CommonImageProcessingHelper;
import at.fhv.framework.events.ImageEvent;
import at.fhv.framework.listeners.ImageProcessingListener;
import at.fhv.framework.listeners.RefireListener;

/**
 * The ImagePanel class.
 * 
 * @author Michael Sieber
 */
public class SaveFilter implements ImageProcessingListener, RefireListener 
{
	private CommonImageProcessingHelper _helper;
	private String _path = "C:/tmp/save.jpg";

	/**
	 * Create a new ImagePanel
	 */
	public SaveFilter() {
		_helper = new CommonImageProcessingHelper(this);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void imageChanged(ImageEvent event) {
		// save
		BufferedImage bi = event.getImage().getAsBufferedImage();
		File outputfile = new File(_path);
		try {
			ImageIO.write(bi, "jpg", outputfile);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void addRefireListener(RefireListener listener) {
		_helper.addRefireListener(listener);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void removeRefireListener(RefireListener listener) {
		_helper.removeRefireListener(listener);
	}

	/*
	 * {@inheritDoc}
	 */
	@Override
	public void refire() {
		// nothing to do here
	}

	/**
	 * @return The path
	 */
	public String getPath() {
		return _path;
	}

	/**
	 * @param path The path to set
	 */
	public void setPath(String path) {
		_path = path;
	}

}
